package com.ycfmedical.bed.adapter;

import android.content.Context;
import android.support.v4.view.GestureDetectorCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;

import com.ycfmedical.bed.R;
import com.zhy.autolayout.utils.AutoUtils;

import cn.droidlover.xdroidmvp.base.SimpleRecAdapter;

/**
 * Created by Administrator on 2017-04-15.
 */

public class Vs_measureAdapter extends SimpleRecAdapter<String, Vs_measureAdapter.MyViewHolder>{
    final static int BUTTON = 0;
    private int layoutPosition;

    public Vs_measureAdapter(Context context) {
        super(context);
    }

    @Override
    public MyViewHolder newViewHolder(View itemView) {
        return new MyViewHolder(itemView);
    }

    @Override
    public int getLayoutId() {
        return R.layout.item_view;
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
        final String mText = data.get(position);
        holder.vsMeasureBtn.setText(data.get(position));
        holder.itemView.setTag(mText);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //获取当前点击的位置
                layoutPosition = holder.getLayoutPosition();
                notifyDataSetChanged();
                if (getRecItemClick() != null) {
                    getRecItemClick().onItemClick(position, mText, BUTTON, holder);
                }
            }
        });

        //更改状态
        if (position == layoutPosition) {
            holder.vsMeasureBtn.setBackgroundResource(R.drawable.vs_measure);
        } else {
            holder.vsMeasureBtn.setBackgroundResource(R.drawable.vs_measure_true);
        }
    }

    public static class MyViewHolder extends RecyclerView.ViewHolder {
        public Button vsMeasureBtn;
        public MyViewHolder(View itemView) {
            super(itemView);
            vsMeasureBtn = (Button) itemView.findViewById(R.id.vs_measure_btn);
            AutoUtils.auto(itemView);
        }
    }

}
